// 加入购物车
// POST
// /member/cart

import { http } from '@/utils/https'
import type { CartItem } from '@/types/cart'

/**
 * 加入购物车
 * @param skuId SKUID
 * @param count 数量
 */
export const postMemberCartApi = (skuId: string, count: number) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data: {
      skuId,
      count,
    },
  })
}

//
// 购物车
// 获取购物车列表
// GET
// /member/cart

/**
 * 获取购物车列表
 */
export const getMemberCartApi = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}

//
// 购物车
// 删除/清空购物车单品
// DELETE
// /member/cart

/**
 * 删除/清空购物车单品
 * @param ids
 */
export const deleteMemberCartApi = (ids: []) => {
  return http({
    method: 'DELETE',
    url: '/member/cart',
    data: {
      ids,
    },
  })
}

// 修改购物车单品
// PUT
// /member/cart/{skuId}

/**
 * 修改购物车单品
 * @param skuId
 * @param data selected:是否选中，count：数量
 */
export const putMemberCartBySkuIdApi = (
  skuId: string,
  data: { selected?: boolean; count?: number },
) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}

// 购物车全选/取消全选
// PUT
// /member/cart/selected
/**
 * 购物车全选/取消全选
 */
export const putMemberCartSelectedApi = (data: { selected: boolean }) => {
  return http({
    method: 'PUT',
    url: '/member/cart/selected',
    data,
  })
}
